/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cognition.util.marshal;

/**
 *
 * @author richard
 */
public class LongMarshaller {
    public static final int MARSHAL_SIZE = 8;

    public static long unmarshal(byte[] b) throws IllegalArgumentException {
        if (b == null || b.length < MARSHAL_SIZE)
            throw new IllegalArgumentException(
                    "Cannot unmarshal a byte array that is null or too short.");

        return (long)(
            (int) (0xff & b[0]) << 56 |
            (int) (0xff & b[1]) << 48 |
            (int) (0xff & b[2]) << 40 |
            (int) (0xff & b[3]) << 32 |
            (int) (0xff & b[4]) << 24 |
            (int) (0xff & b[5]) << 16 |
            (int) (0xff & b[6]) << 8  |
            (int) (0xff & b[7]) << 0);

    }

}
